import config from '@/views/tankGame/config';

export type keyType = keyof typeof config.images;

export const imageMap = new Map<keyType, HTMLImageElement>();

export const getImgTag = Object.entries(config.images).map(([key, value]) => {
  try {
    return new Promise((resolve) => {
      const img: HTMLImageElement = document.createElement('img');
      img.src = value;
      img.onload = () => {
        imageMap.set(key as keyType, img);
        resolve(img);
      };
    });
  } catch (error) {
    console.log(error);
  }
});
